<template>
	<view class="personal">
		<view class="list">
			<view class="list-item">
				<text>店铺名称</text>
				<view class="input"><input class="inputText" type="text"  data-name="name" @input="input" :value="applyData.name" placeholder="店铺名称" placeholder-class="placeholder" /></view>
			</view>
			<view class="list-item">
				<text>手机号</text>
				<view class="input"><input class="inputText" type="text"  data-name="phone" @input="input" :value="applyData.phone" placeholder="手机号" placeholder-class="placeholder" /></view>
			</view>
			<view class="list-item">
				<text>地址</text>
				<view class="input"><input class="inputText" type="text"  data-name="address" @input="input" :value="applyData.address" placeholder="详细地址" placeholder-class="placeholder" /></view>
			</view>
		</view>
		<view class="block"></view>
		<view class="pannel">
			<view class="title"><text>|&nbsp;营业执照</text></view>
			<view class="uploader_one" @tap="upload('business_license')">
				<view class="up_one" v-if="applyData.business_license"><image class="bg" :src="applyData.business_license" mode="widthFix"></image></view>
				<view class="up_one">
					<image class="camera_gray" src="../../../static/camera_gray.png" mode="widthFix"></image>
					<text>上传营业执照</text>
				</view>
			</view>
		</view>
		<view class="pannel">
			<view class="title"><text>|&nbsp;经营许可证</text></view>
			<view class="uploader_one" @tap="upload('license_operation')">
				<view class="up_one" v-if="applyData.license_operation"><image class="bg" :src="applyData.license_operation" mode="widthFix"></image></view>
				<view class="up_one">
					<image class="camera_gray" src="../../../static/camera_gray.png" mode="widthFix"></image>
					<text>经营许可证</text>
				</view>
			</view>
		</view>
		<view class="block"></view>
	<view class="btn" v-if="applyData.is_verfiy === null" @tap="submit()">提交审核</view>
	<view class="btn" v-if="applyData.is_verfiy === 0">审核中</view>
	<view class="btn" v-if="applyData.is_verfiy === 1">审核通过</view>
	<view class="btn" v-if="applyData.is_verfiy === 2">不符合</view>
	</view>
</template>

<script>
import uniIcons from '@/components/uni-icons/uni-icons.vue';
import config from '../../../common/request/config.json';
export default {
	components: { uniIcons },
	data() {
		return {
			applyData: {
				name: '',
				phone: '',
				address: '',
				business_license: '',
				license_operation: '',
				is_verfiy: null
			}
		};
	},
	onLoad() {
		// this.getData();
	},
	methods: {
		upload(type) {
			uni.chooseImage({
				count: 1,
				sizeType: ['original'],
				success: res => {
					let imagePath = res.tempFilePaths[0];
					uni.uploadFile({
						url: config.baseUrl + '/setting/uplodeImg',
						filePath: imagePath,
						name: 'file',
						success: uploadRes => {
							let data = JSON.parse(uploadRes.data);
							let url = data.data.list;
							this.applyData[type] = url;
						}
					});
				}
			});
		},
		async getData() {
			let res = await this.$request.get('/mine/applyShop', {});
			if (res.data.code != 1000) {
				uni.showToast({
					title: res.data.msg,
					icon: 'none',
					duration: 2000
				});
				setTimeout(function() {
					uni.navigateTo({
						url: '/pages/house_property/set/enterprise/enterprise'
					});
				}, 2000);
				return;
			}
			let data = res.data.data.list;
			if (data) {
				let { name, phone, address, business_license, license_operation, is_verfiy } = data;
				this.applyData = {
					name,
					phone,
					address,
					business_license,
					license_operation,
					is_verfiy
				};
			}
		},
		input(e) {
			let name = e.target.dataset.name;
			let value = e.detail.value;
			this.applyData[name] = value;
		},
		async submit() {
			let applyData = this.applyData;
			for (let key in applyData) {
				if (!applyData[key] && key != 'is_verfiy') {
					uni.showToast({
						title: '请将表单填写完整',
						duration: 2000
					});
					console.log(key);
					return false;
				}
			}
			let res = await this.$request.post('/mine/applyShop', {
				data: {
					...applyData
				}
			});
			if (res.data.code == 10000) {
				uni.showToast({
					title: '提交成功',
					duration: 2000
				});
				setTimeout(() => {
					uni.navigateBack({
						delta: 1
					});
				}, 2000);
			} else {
				uni.showToast({
					title: '提交失败',
					duration: 2000
				});
			}
		}
	}
};
</script>

<style lang="scss">
.personal {
	padding-bottom: 300upx;
}
.list {
	width: 100%;
	box-sizing: border-box;
	padding-left: 30upx;
	.list-item {
		width: 100%;
		height: 110upx;
		border-bottom: 2upx solid #e7e7e7;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding-right: 20upx;
		font-size: $uni-font-size-base;
		color: #333333;
		.input {
			width: 500upx;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			.inputText {
				color: #333333;
				font-size: $uni-font-size-base;
				width: 100%;
				text-align: right;
				box-sizing: border-box;
			}
		}
		.code {
			width: 500upx;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			text {
				font-size: $uni-font-size-base;
				color: #f33131;
				height: 100%;
				line-height: 110upx;
			}
			.inputText {
				color: #333333;
				font-size: $uni-font-size-base;
				width: 300upx;
				text-align: right;
				box-sizing: border-box;
				padding-right: 30upx;
			}
		}
	}
}
.pannel {
	width: 100%;
	background-color: #ffffff;
	margin-top: 20upx;
	border-radius: 20upx;
	box-sizing: border-box;
	padding: 20upx;
	.title {
		width: 100%;
		color: #f34b32;
		line-height: 1.5em;
		font-size: $uni-font-size-lg;
	}
	.uploader {
		width: 100%;
		padding: 20upx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		.image {
			width: 320upx;
			position: relative;
			.bg {
				width: 100%;
			}
			.camera {
				width: 80upx;
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
			}
		}
		.text {
			line-height: 1.5em;
			font-size: $uni-font-size-base;
			color: #333333;
			text-align: center;
		}
	}
	.uploader_one {
		width: 100%;
		padding: 20upx;
		box-sizing: border-box;
		display: flex;
		justify-content: flex-start;
		.up_one {
			width: 200upx;
			height: 200upx;
			box-sizing: border-box;
			border: 4upx solid #e7e7e7;
			border-radius: 20upx;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			margin-left: 20upx;
			overflow: hidden;
			.bg {
				width: 100%;
			}
			.camera_gray {
				width: 80upx;
			}
			text {
				font-size: $uni-font-size-sm;
				color: #999999;
				margin-top: 15upx;
			}
		}
	}
}
.placeholder {
	color: #d7d7d7;
}
.block {
	width: 100%;
	height: 20upx;
	background-color: #f5f6f7;
}
.btn {
	width: 600upx;
	margin: 0 auto;
	margin-top: 150upx;
	height: 100upx;
	line-height: 100upx;
	border-radius: 50upx;
	text-align: center;
	font-size: $uni-font-size-lg;
	color: #fff;
	background: linear-gradient(left, #ff5d42, #f33632);
}
</style>
